(function () {
  function Post(url, data) {
    return new Promise((resolve, reject) => {
      let request = new XMLHttpRequest()
      request.open('post', url)
      request.setRequestHeader('content-type', 'application/json')
      request.onreadystatechange = function () {
        if (request.readyState === 4) {
          resolve(JSON.parse(request.response))
        }
      }
      request.send(JSON.stringify(data))
    })
  }

  let testURL = 'http://124.127.117.217:58000'
  let productionURL = 'http://10.143.19.57:29001'

  let urlList = [
    '/northbound/getAllPhysicalTerminationPoints',
    '/northbound/getAllFloatingTerminationPoints',
    '/northbound/getConnectionTerminationPoints',
    '/northbound/getEquipments'
  ]

  let data = {
    ip: "10.1.20.2",
    devId: "98:00:74:6d:d4:bc"
  }

  async function go(url) {
    Post(testURL + url, data).then(res => {
      let ans = []
      let key = Object.keys(res.data)[0]
      ans = res.data[key].filter(val => 'name' in val)
      console.log(`%c${url} : ${ans.length}`, 'color: #66e876')
    }).catch(() => {
      console.log(`%c${url}`, 'color: red')
    })
  }

  for (let i = 0; i < urlList.length; ++i) {
    go(urlList[i])
  }
})()
